/*
 * Testing.c
 *
 *  Created on: 15.10.2011
 *      Author: wink
 */

#include <avr/io.h>
#include "Globals.h"
#include "ButtonControl.h"
#include "LightControl.h"
#include "TimeDate.h"
#include "Alarm.h"
#include "ShiftRegControl.h"

void TestButtonIndEnter( T_ButtonReason iReason );
void TestButtonIndUp( T_ButtonReason iReason );
void TestButtonIndDown( T_ButtonReason iReason );
void TestButtonIndBack( T_ButtonReason iReason );
void TestButtonIndCap( T_ButtonReason iReason_t );

void TestCyclic( void )
{

}

void TestInit( void )
{
  BcoRegisterNotification( TestButtonIndUp, Button_Low2High, Button_Right );
  BcoRegisterNotification( TestButtonIndEnter, Button_Low2High, Button_Enter );
  BcoRegisterNotification( TestButtonIndDown, Button_Low2High, Button_Left );
  BcoRegisterNotification( TestButtonIndBack, Button_Low2High, Button_Back );
  BcoRegisterNotification( TestButtonIndCap, Button_ExtHigh2Low, Button_Cap );
}

void TestButtonIndUp( T_ButtonReason iReason )
{
  static uint8_t lTempButton_u8 = 0;
    if( 5 < ++lTempButton_u8 )
    {
      const uint8_t cTimeUpdateMin_u8 = 2;
      lTempButton_u8 = 0;
      T_Time lTime_t;
      T_Alarm lAlarm_t;
      TidGetTime( &lTime_t );
      lAlarm_t.State_t        = Alarm_Enabled;
      lAlarm_t.LightMode_t    = 15;
      lAlarm_t.SoundMode_t    = Alarm_Sound1;
      lAlarm_t.Days_t         = Alarm_Weekend | Alarm_Weekdays;
      lAlarm_t.Time_t.Second  = 0;
      lAlarm_t.Sleep_t        = 5;

      if( lTime_t.Minute + cTimeUpdateMin_u8 >= TIME_MIN_MAX )
      {
        lAlarm_t.Time_t.Hour    = lTime_t.Hour+1;
        lAlarm_t.Time_t.Minute  = lTime_t.Minute+cTimeUpdateMin_u8-TIME_MIN_MAX;
      }
      else
      {
        lAlarm_t.Time_t.Hour    = lTime_t.Hour;
        lAlarm_t.Time_t.Minute  = lTime_t.Minute+cTimeUpdateMin_u8;
      }
      AlaSetAlarm( &lAlarm_t, 2 );
    }
}

void TestButtonIndDown( T_ButtonReason iReason )
{

}

void TestButtonIndEnter( T_ButtonReason iReason )
{
  static uint8_t lTempButton_u8 = 0;
  if( 5 < ++lTempButton_u8 )
  {
    const uint8_t cTimeUpdateMin_u8 = 48;
    lTempButton_u8 = 0;
    T_Time lTime_t;
    T_Alarm lAlarm_t;
    TidGetTime( &lTime_t );
    lAlarm_t.State_t        = Alarm_Enabled;
    lAlarm_t.LightMode_t    = 45;
    lAlarm_t.SoundMode_t    = Alarm_SoundOff;
    lAlarm_t.Days_t         = Alarm_Weekend | Alarm_Weekdays;
    lAlarm_t.Time_t.Second  = 0;
    lAlarm_t.Sleep_t        = 5;

    if( lTime_t.Minute + cTimeUpdateMin_u8 >= TIME_MIN_MAX )
    {
      lAlarm_t.Time_t.Hour    = lTime_t.Hour+1;
      lAlarm_t.Time_t.Minute  = lTime_t.Minute+cTimeUpdateMin_u8-TIME_MIN_MAX;
    }
    else
    {
      lAlarm_t.Time_t.Hour    = lTime_t.Hour;
      lAlarm_t.Time_t.Minute  = lTime_t.Minute+cTimeUpdateMin_u8;
    }
    AlaSetAlarm( &lAlarm_t, 3 );
  }
}

void TestButtonIndBack( T_ButtonReason iReason )
{
  static uint8_t lTempButton_u8 = 0;
  if( 5 < ++lTempButton_u8 )
  {
    const uint8_t cTimeUpdateMin_u8 = 5;
    lTempButton_u8 = 0;
    T_Time lTime_t;
    T_Alarm lAlarm_t;
    TidGetTime( &lTime_t );
    lAlarm_t.State_t        = Alarm_Enabled;
    lAlarm_t.LightMode_t    = 15;
    lAlarm_t.SoundMode_t    = Alarm_Sound1;
    lAlarm_t.Days_t         = Alarm_Weekend | Alarm_Weekdays;
    lAlarm_t.Time_t.Second  = 0;
    lAlarm_t.Sleep_t        = 5;

    if( lTime_t.Minute + cTimeUpdateMin_u8 >= TIME_MIN_MAX )
    {
      lAlarm_t.Time_t.Hour    = lTime_t.Hour+1;
      lAlarm_t.Time_t.Minute  = lTime_t.Minute+cTimeUpdateMin_u8-TIME_MIN_MAX;
    }
    else
    {
      lAlarm_t.Time_t.Hour    = lTime_t.Hour;
      lAlarm_t.Time_t.Minute  = lTime_t.Minute+cTimeUpdateMin_u8;
    }
    AlaSetAlarm( &lAlarm_t, 4 );
  }
}

void TestButtonIndCap( T_ButtonReason iReason_t )
{
  T_ShiftValues lValues_t = { 0x5A };
  SrcSetValues( &lValues_t );
}
